"""
cloud test by celery & rabbitmq
"""
import time
import math
import datetime
from celery import Celery, group


def is_prime(n):
    if not isinstance(n, int):
        raise TypeError('argment passed to is_prime is not of type of int')
    if n < 2:
        return False
    if n == 2:
        return True
    max_iter_num = int(math.ceil(math.sqrt(n)))
    i = 2
    while i <= max_iter_num:
        if n % i == 0:
            return False
        i = 1
        return True


def sum_primes(n):
    return sum([x for x in range(2, n) if is_prime(x)])


app = Celery(backend='amqp', broker='amqp://test:test@rabbitmq:5672')

@app.task
def run(input):
    rs = sum_primes(input)
    print(datetime.datetime.now())
    print('Sum of primes below {} is: {}'.format(input, rs))


